// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.ui;

import zombie.core.SpriteRenderer;
import zombie.core.textures.Texture;

public final class VehicleGauge extends UIElement {
    protected int needleX;
    protected int needleY;
    protected float minAngle;
    protected float maxAngle;
    protected float value;
    protected Texture texture;
    protected int needleWidth = 45;

    public VehicleGauge(Texture _texture, int _needleX, int _needleY, float _minAngle, float _maxAngle) {
        this.texture = _texture;
        this.needleX = _needleX;
        this.needleY = _needleY;
        this.minAngle = _minAngle;
        this.maxAngle = _maxAngle;
        this.width = (float)_texture.getWidth();
        this.height = (float)_texture.getHeight();
    }

    public void setNeedleWidth(int newSize) {
        this.needleWidth = newSize;
    }

    @Override
    public void render() {
        if (this.isVisible()) {
            super.render();
            this.DrawTexture(this.texture, 0.0, 0.0, 1.0);
            double double0 = this.minAngle < this.maxAngle
                ? Math.toRadians((double)(this.minAngle + (this.maxAngle - this.minAngle) * this.value))
                : Math.toRadians((double)(this.maxAngle + (this.maxAngle - this.minAngle) * (1.0F - this.value)));
            double double1 = (double)this.needleX;
            double double2 = (double)this.needleY;
            double double3 = (double)this.needleX + (double)this.needleWidth * Math.cos(double0);
            double double4 = Math.ceil((double)this.needleY + (double)this.needleWidth * Math.sin(double0));
            int int0 = this.getAbsoluteX().intValue();
            int int1 = this.getAbsoluteY().intValue();
            SpriteRenderer.instance
                .renderline(null, int0 + (int)double1, int1 + (int)double2, int0 + (int)double3, int1 + (int)double4, 1.0F, 0.0F, 0.0F, 1.0F);
        }
    }

    public void setValue(float _value) {
        this.value = Math.min(_value, 1.0F);
    }

    public void setTexture(Texture newText) {
        this.texture = newText;
    }
}
